Skip to content

feat(db): verify database schema matches code on startup (#352) - #537

Merged
Miracle656 merged 1 commit into
Divinity-Labs:mainfrom
sparkysolutions10-pixel:feat/db-schema-startup-verification-352
Oct 22, 2026
Merged

Miracle656 merged 1 commit into
Divinity-Labs:mainfrom
sparkysolutions10-pixel:feat/db-schema-startup-verification-352

Conversation

@sparkysolutions10-pixel

Copy link
Copy Markdown
Contributor

Closes #352

Summary of Changes

  • Implements assertSchemaValid() in src/db/schemaVerify.ts checking for existence of all required tables and columns against PostgreSQL information_schema on boot.
  • Fails fast and throws DatabaseSchemaMismatchError explicitly naming any missing tables or columns before request handling begins.
  • Integrated into src/index.ts immediately after pgPool.connect().
  • Documents why the project currently utilizes prisma db push instead of migrations, outlining the architectural trade-offs and future transition path to prisma migrate in docs/database-schema.md.
  • Added unit tests in src/__tests__/schemaVerification.test.ts.

@Miracle656
Miracle656 merged commit dd8e301 into Divinity-Labs:main Oct 22, 2026
Miracle656 added a commit that referenced this pull request Oct 22, 2026
  tsc --noEmit   clean
  vitest         100 files, 1146 passing (up from 99 / 1140)

  #557  operations runbook
  #537  verify the database schema matches the code on start-up
  #536  send a graceful close frame to WebSocket clients on shutdown

The dropped-tests guard flagged one case, and it was the good kind:

  - src/__tests__/fanout.test.ts :: destroy cleans up all state

renamed to "destroy cleans up all state idempotently" and joined by two new
shutdown cases. Strengthened, not lost. That is the second time today the
guard surfaced a rename rather than a deletion, which is the point of it --
the decision gets made either way.

A note on #537, because start-up checks have a history here. It verifies the
schema matches the code; it does not refuse to boot over a partial dependency.
That distinction matters: a startup validator merged into wraith two days ago
made a missing per-network RPC URL fatal and crash-looped the service for
forty minutes. A schema mismatch genuinely does make the whole process
useless, so this one is on the right side of the line.

Claude-Session: https://claude.ai/code/session_01USgemLt4Rnz4SGB1Srf3GB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Startup does not verify the database schema matches the code

2 participants